@extends('admin.base')

@section('content')
    <div class="layui-card">
        <blockquote class="layui-elem-quote form-inline layui-form" style="font-size: 14px;padding: 10px">
                <div class="layui-inline" style="margin: 3px 0;">
                    <label class="control-label" for="title" style="font-weight: bold">用户手机号</label>：
                    <div class="layui-input-inline">
                        <input type="text" id="user_phone" class="layui-input" name="user_phone" >
                    </div>
                </div>
            <div class="layui-inline" style="margin: 3px 0;">
                <label class="control-label" for="title" style="font-weight: bold">内容</label>：
                <div class="layui-input-inline">
                    <input type="text" id="content" class="layui-input" name="content" >
                </div>
            </div>
                <div class="layui-inline" style="margin: 3px 0;">
                    <label class="control-label" for="status" style="font-weight: bold">状态</label>：
                    <div class="layui-input-inline">
                        <select id="status">
                            <option value="">全部</option>
                            <option value="1">未读</option>
                            <option value="2">已读</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin: 3px 0;">
                    <label class="control-label" for="timestp1" style="font-weight: bold">反馈时间</label>：
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input"  name="timestp1" id="timestp1">
                    </div>
                    <label class="control-label" for="timestp2">-</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="timestp2" id="timestp2">
                    </div>
                </div>

                <div class="layui-inline" style="margin: 3px 0;">
                    <button id="searchBtn" type="button" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="wheelfilter" style="height: 36px;line-height: 36px;">搜索</button>
                        <button class="layui-btn layui-btn-sm layui-btn-danger" style="height: 36px;line-height: 36px;" id="listDelete">标记为已读</button>
                </div>
        </blockquote>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="client">
               @{{# if(d.client==1){ }}
                Android
                @{{# }if(d.client==2){ }}
                IOS
                @{{# } }}
            </script>
            <script type="text/html" id="statusText">
                @{{# if( d.status==1 ){ }}
                <span class="layui-badge">未读</span>
                @{{# }if( d.status==2 ){ }}
                <span class="layui-badge layui-bg-green">已读</span>
                @{{# } }}
            </script>
            <script type="text/html" id="thumb">
                <a href="../storage/@{{d.thumb}}" target="_blank" title="点击查看"><img src="../storage/@{{d.thumb}}" alt="" width="28" height="28"></a>
            </script>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    @{{# if( d.status==1 ){ }}
                    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">标记为已读</button>
                    @{{# }if( d.status==2 ){ }}
                    <button class="layui-btn layui-btn-danger layui-btn-sm layui-disabled" lay-event="del" disabled>标记为已读</button>
                    @{{# } }}
                </div>
            </script>
        </div>
    </div>
@endsection

@section('script')
    @can('app.feedback')
        <script>
            layui.use(['layer','table','form'],function () {
                var layer = layui.layer;
                var form = layui.form;
                var table = layui.table;
                //用户表格初始化

                var dataTable = table.render({
                    elem: '#dataTable'
                    ,height: 'full-200'
                    ,url: "{{ route('admin.feedback.data') }}" //数据接口
                    ,page: true //开启分页
                    ,limit: 10 //限制条数
                    ,cols: [[ //表头
                        {checkbox: true,fixed: true}
                        ,{field: 'id', title: 'ID',sort: true,width:80}
                        ,{field: 'user_phone', title: '用户手机号'}
                        ,{field: 'content', title: '内容'}
                        ,{field: 'contact', title: '联系方式'}
                        ,{field: 'client', title: '客户端', toolbar: '#client'}
                        ,{field: 'version', title: '版本'}
                        ,{field: 'status', title: '状态',templet: '#statusText'}
                        ,{field: 'timestp', title: '反馈时间'}
                        ,{fixed: 'right',title: '操作', width: 120, align:'center', toolbar: '#options'}
                    ]]
                });

                //监听工具条
                table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                    if(layEvent === 'del'){
                        layer.confirm('确定标记为已读吗？', function(index){
                            $.post("{{ route('admin.feedback.read') }}",{_method:'put',ids:[data.id]},function (result) {
                                if (result.code==0){
                                    obj.update({
                                        status: 2
                                    });
                                    layer.msg(result.msg,{icon:6});
                                }else {
                                    layer.msg(result.msg,{icon:5})
                                }
                                layer.close(index);
                            });
                        });
                    } else if(layEvent === 'edit'){
                        location.href = '/admin/wheelpicture/'+data.id+'/edit';
                    }
                });

                //按钮批量删除
                $("#listDelete").click(function () {
                    var ids = []
                    var hasCheck = table.checkStatus('dataTable')
                    var hasCheckData = hasCheck.data
                    if (hasCheckData.length>0){
                        $.each(hasCheckData,function (index,element) {
                            ids.push(element.id)
                        })
                    }
                    if (ids.length>0){
                        layer.confirm('确定标记为已读吗？', function(index){
                            $.post("{{ route('admin.feedback.read') }}",{_method:'put',ids:ids},function (result) {
                                if (result.code==0){
                                    dataTable.reload();
                                    layer.msg(result.msg,{icon:6})
                                }else {
                                    layer.msg(result.msg,{icon:5})
                                }
                                layer.close(index);
                            });
                        })
                    }else {
                        layer.msg('请选择已读项')
                    }
                })
                //搜索
                $("#searchBtn").click(function () {
                    var user_phone = $("#user_phone").val();
                    var content = $("#content").val();
                    var status = $("#status").val()
                    var timestp1 = $("#timestp1").val();
                    var timestp2 = $("#timestp2").val()
                    dataTable.reload({
                        where:{
                            user_phone:user_phone,
                            content:content,
                            status:status,
                            timestp1:timestp1,
                            timestp2:timestp2
                        }
                    })
                })
            })
            layui.use('laydate', function(){
                var laydate = layui.laydate;
                //日期时间选择器
                laydate.render({
                    elem: '#timestp1'
                    ,type: 'datetime'
                });
                laydate.render({
                    elem: '#timestp2'
                    ,type: 'datetime'
                });

            });
        </script>
    @endcan
@endsection